const express = require("express");
var router = express.Router()

//引入模块
const user = require("./admin/user")
const login = require("./admin/login")
const nav = require("./admin/nav")
const manager = require("./admin/manager")


const url = require('url')
    // 权限判读
router.use((req, res, next) => {
    const pathname = url.parse(req.url).pathname
    if (req.session.userinfo && req.session.userinfo.username) {
        next()
    } else {
        if (pathname == '/login' || pathname == '/login/doLogin' || pathname == '/login/captcha') {
            next()
        } else {
            res.redirect('/admin/login')
        }
    }
})
router.get("/", (req, res) => {
        res.send("后台管理中心")
    })
    //挂载路由
router.use("/user", user)
router.use("/login", login)
router.use("/nav", nav)
router.use("/manager", manager)

module.exports = router